package com.zy.configs;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: shopping153_cloud
 * @description:
 * @author: zy
 * @create: 2025-08-19 15:03
 */
@Configuration
@Data
@ConfigurationProperties(prefix="aliyun.oss")   // 方案一: 完成自动配置的读取

//@PropertySource("classpath:application.yml")  //方案二: 指定要读取的配置文件，再利用@Value完成di
public class OssConfig {
   // @Value("${aliyun.oss.endpoint}")
    private String endpoint;
   // @Value("${aliyun.oss.access-key-id}")
    private String accessKeyId;
    //@Value("${aliyun.oss.access-key-secret}")
    private String accessKeySecret;
    //@Value("${aliyun.oss.bucket-name}")
    private String bucketName;
    //@Value("${aliyun.oss.url-prefix}")
    private String urlPrefix;

    @Bean
    public OSS ossClient(){
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}
